package edu.gatech.ors.mrsim.helpers;

import java.io.FileOutputStream;
import java.io.PrintWriter;


/**
 * Troy's class for generating boilerplate code
 * @author tdoneal
 *
 */
public class ClassGenUtil {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String[] classNames = {"Read","Write","Delete","Create","GetFileChecksum","MkDir","Open","Rename","SetPermission"};

		writeFile("o.txt",genBPClasses(classNames,"SimTask",new JDGenBPTask()));
		
	}
	
	public static void writeFile(String fp, String fc){
		try {
			FileOutputStream fos = new FileOutputStream(fp);
			PrintWriter pw = new PrintWriter(fos);
			pw.write(fc);
			fos.flush();
			pw.close();
			fos.close();
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	
	
	
	public static abstract class JDGen{
		public abstract String genJDText(String className,String extend);
	}
	
	public static class JDGenBPTask extends JDGen {

		@Override
		public String genJDText(String className, String extend) {
			return "Represents the "+className+" simulation task.";
		}
		
	}

	public static String genBPClasses(String[] names,String extend,JDGen jdgen){
		StringBuilder sb = new StringBuilder();
		for (int i = 0;i<names.length;i++){
			String name = names[i];
			if (jdgen!=null){
				sb.append("/**\n");
				sb.append(" * "+jdgen.genJDText(name,extend)+"\n");
				sb.append(" */ \n");
			}
			sb.append("public static class "+name+((extend==null)?"":(" extends "+extend))+" { \n");
			sb.append("\tpublic "+name+"() {\n");
			sb.append("\t\t\n");
			sb.append("\t}\n");
			sb.append("}\n\n");
		}
		return sb.toString();
	}

}
